{include file="common/comm_header" /}

<style>
    .cus-label-width-15{
        width: 15%;
    }
    .cus-layui-input-inline{
        width: 75%;
        display:inline-block;
        vertical-align:middle;
    }
    .cus-width-center{
        width: 75%;
        text-align: center;
    }
</style>
<body>
{if condition="empty($nodeTemplateData)"}
<div class="x-body layui-anim layui-anim-up">
    <h1>出现异常</h1>
</div>
{else /}
<div class="x-body layui-anim layui-anim-up">
    <div style="text-align: center;font-size: 22px;color: red;padding-bottom: 20px;">
        <b>注意：</b>域名不带http或https！示例: xxx.xxx.com 或 xxx.com
    </div>
    <form class="layui-form">
        <input type="hidden" name="node_template_id" readonly="readonly" value="{$nodeTemplateData.id}">

        <div class="layui-form-item">
            <label  for="L_node_title" class="layui-form-label cus-label-width-15">
                网站标题：
            </label>
            <div class="cus-layui-input-inline">
                <input type="text" name="node_title" maxlength="60" id="L_node_title" value="{$nodeTemplateData.node_title}" autocomplete="off" class="layui-input" lay-verify="node_title">
                <div class="layui-form-mid layui-word-aux">
                    最长60字符
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_node_url" class="layui-form-label cus-label-width-15">
                网站URL：
            </label>
            <div class="cus-layui-input-inline">
                <input type="text" maxlength="100" name="node_url" id="L_node_url" value="{$nodeTemplateData.node_url}" autocomplete="off" class="layui-input" lay-verify="node_url">
                <div class="layui-form-mid layui-word-aux">
                    不能重复，最长100字符
                </div>
            </div>

        </div>

        <div class="layui-form-item">
            <label for="L_config_value" class="layui-form-label cus-label-width-15">
                当前使用模板：
            </label>
            <div class="cus-layui-input-inline">
                <select name="template_data" id="L_config_value" lay-verify="template_data">
                    {volist name="templateConfigData" id="vo"}
                    <option value="{$vo.id}+{$vo.config_value}" {eq name="$vo.id" value="$nodeTemplateData.config_id"}selected{/eq}>{$vo.config_title}【{$vo.config_value}】</option>
                    {/volist}
                </select>
            </div>
        </div>

        <!--提交按钮-->
        <div class="layui-form-item">
            <label for="L_config_value" class="layui-form-label cus-label-width-15">
            </label>
            <div class="cus-width-center">
                <button id="addAssort"  class="layui-btn" lay-filter="edit" lay-submit="">
                    修改
                </button>
            </div>

        </div>
    </form>
</div>
<script type="text/javascript" src="/static/common/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin//lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/static/admin//js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="/static/common/js/html5.min.js"></script>
<script src="/static/common/js/respond.min.js"></script>
<![endif]-->
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
                ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            node_url: function(value){
                var valLen = value.length;
                if(valLen < 1){
                    return '网站URL不能为空';
                }
                if(valLen >100){
                    return 'URL太长了！';
                }
            },
            node_title: function(value){
                var valLen = value.length;
                if(valLen < 1){
                    return '网站标题不能为空';
                }
                if(valLen >60){
                    return '标题太长了！';
                }
            }
        });

        //监听提交
        form.on('submit(edit)', function(data){
            ///提交修改
            $('#addAssort').attr('disabled',true);
            $.ajax({
                url:'/{$Think.ADMIN_ROUT_PREFIX}/template-edit/'+Math.random(),
                timeout : 2000,
                type : 'post',
                data :{node_template_id:data.field.node_template_id,node_title:data.field.node_title,node_url:data.field.node_url,template_data:data.field.template_data},
                async: false,
                dataType:'json',
                success:function(data){
                    var testJson = $.parseJSON(data);
                    if(testJson.status == 0){
                        layer.alert(testJson.msg, {
                            icon: 6,
                            time: 1000,
                            closeBtn:0,
                            end:function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                            }
                        });
                    }else if(testJson.status == 2){
                        layer.alert(testJson.msg, {
                            icon: 5,
                            time: 2000
                        });
                        $('#addAssort').attr('disabled',false);
                        return false;
                    }else{
                        layer.alert('出现异常', {
                            icon: 5,
                            time: 2000
                        });
                        $('#addAssort').attr('disabled',false);
                        return false;
                    }
                },
                error:function(){
                    layer.alert('出现异常，建议刷新页面。', {
                        icon: 5,
                        time: 2000
                    });
                    $('#addAssort').attr('disabled',false);
                    return false;
                }
            });

            return false;
        });


    });
</script>
{/if}
</body>

{include file="common/comm_bottom" /}